import { defineStore } from 'pinia'
import cartApi, { type CartModelList } from '@/api/cart'

const initCartData = (): CartModelList => ({
    "cartList":[
        {
            "id":0,
            "imgUrl":"",
            "Product":"",
            "type":"",
            "price":1,
            "number":0,
            "ischeck":true
        }
    ],
    "cartList2":[
        {
            "id":0,
            "imgUrl":"",
            "Product":"",
            "type":"",
            "price":2,
            "number":0,
            "ischeck":true
        }
    ]
})

const useCartStore = defineStore('cartlist', {
  state: () => ({
    cartData: initCartData()
  }),
  actions: {
    async getCartData() {
      try {
        let result = await cartApi.getCart()
        this.cartData = result.data
        // console.log(result.data)
        // console.log(this.cartData)
      } catch (error) {
        console.log('获取数据失败,请重试')
      }
    }
  },
  getters: {}
})

export default useCartStore